package com.kevin.aqmp.producer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * SpringBoot消息生产者测试
 *
 * @author Kevin Liu
 * @date 2020/8/9 上午11:22
 */
@Component
public class PlainQueueSender implements CommandLineRunner {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private RabbitmqConfirmCallback rabbitmqConfirmCallback;


    @Override
    public void run(String... args) throws Exception {
        //指定 ConfirmCallback
        rabbitTemplate.setConfirmCallback(rabbitmqConfirmCallback);
        //指定 ReturnCallback
        rabbitTemplate.setReturnCallback(rabbitmqConfirmCallback);
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend("","first_test_queue","Hello SpringBoot Amqp!");
            System.out.println("发送成功");
        }
    }
}
